# -*- coding: UTF-8 -*-
from Code.Binder.sc_topic import *
from Code.Binder.sc_proxy import get_query_data_binder
from Code.Binder.sc_template import DataTemplate, DataCreater
from Code.Utils.sc_func import Singleton


class ExceptionData(DataTemplate):
    pass


class AppCloseData(DataTemplate):
    pass


class TryLoginData(DataTemplate):
    pass


class NewLoginData(DataTemplate):
    pass


class DelLoginData(DataTemplate):
    pass


class AddImageData(DataTemplate):
    pass


class DelImageData(DataTemplate):
    pass


class StartExecuteData(DataTemplate):
    pass


class StopExecuteData(DataTemplate):
    pass


class UpdateSettingsData(DataTemplate):
    pass


class MakePlotPictureData(DataTemplate):
    pass


class SingleStartData(DataTemplate):
    pass


class SingleUploadData(DataTemplate):
    pass


class SingleDownloadData(DataTemplate):
    pass


@Singleton
class ViewGate(object):
    """ View界面数据代理 """
    single_owner = None  # single_result 非page界面执行结果数据通道独占者 #

    def __init__(self):
        self.query_binder = get_query_data_binder()
        self.app_close_data = DataCreater(AppCloseData)
        self.exception_data = DataCreater(ExceptionData)
        self.try_login_data = DataCreater(TryLoginData)
        self.new_login_data = DataCreater(NewLoginData)
        self.del_login_data = DataCreater(DelLoginData)
        self.add_image_data = DataCreater(AddImageData)
        self.del_image_data = DataCreater(DelImageData)
        self.start_exec_data = DataCreater(StartExecuteData)
        self.stop_exec_data = DataCreater(StopExecuteData)
        self.update_settings_data = DataCreater(UpdateSettingsData)
        self.make_plot_pic_data = DataCreater(MakePlotPictureData)
        # 独立工具，非page界面信号数据， 使用前需要注册并独占结果数据通道 #
        self.single_start_data = DataCreater(SingleStartData)
        self.single_upload_data = DataCreater(SingleUploadData)
        self.single_download_data = DataCreater(SingleDownloadData)

    def query_env_define_data(self, key):
        """ 查询 Model.sc_global.Global 数据"""
        return self.query_binder.query(VIEW_QUERY_ENV_DEFINE_DATA, key)

    def query_settings_data(self, key):
        return self.query_binder.query(VIEW_QUERY_SETTINGS_DATA, key)

    def query_app_title_data(self):
        return self.query_binder.query(VIEW_QUERY_APP_TITLE_DATA)

    def query_about_info_data(self):
        return self.query_binder.query(VIEW_QUERY_ABOUT_INFO_DATA)

    def query_photo_image_data(self, key):
        return self.query_binder.query(VIEW_QUERY_PHOTO_IMAGE_DATA, key)

    def query_plot_image_path(self, key):
        return self.query_binder.query(VIEW_QUERY_PLOT_IMAGE_DATA, key)

    def query_server_dir_data(self):
        return self.query_binder.query(VIEW_QUERY_SERVER_DIR_DATA)

    def query_login_limit_data(self):
        return self.query_binder.query(VIEW_QUERY_LOGIN_LIMIT_DATA)

    def query_preference_ip_data(self):
        return self.query_binder.query(VIEW_QUERY_PREFERENCE_IP_DATA)

    def query_default_pwd_data(self):
        return self.query_binder.query(VIEW_QUERY_DEFAULT_PWD_DATA)

    def query_tree_view_data(self):
        return self.query_binder.query(VIEW_QUERY_TREE_VIEW_DATA)

    def query_widgets_data(self):
        return self.query_binder.query(VIEW_QUERY_WIDGETS_DATA)

    def query_running_task_data(self):
        return self.query_binder.query(VIEW_QUERY_RUNNING_TASK_DATA)

    def query_ips_state_data(self):
        return self.query_binder.query(VIEW_QUERY_IPS_STATE_DATA)

    def query_login_ip_data(self):
        return list(self.query_ips_state_data().keys())

    def query_lang_types_data(self):
        return self.query_binder.query(VIEW_QUERY_LANG_TYPES_DATA)

    def query_language_data(self, *keys):
        return self.query_binder.query(VIEW_QUERY_LANGUAGE_DATA, keys)

    def query_pure_mode_data(self):
        return self.query_binder.query(VIEW_QUERY_PURE_MODE_DATA)

    def register_single_start(self, instance):
        self.single_owner = instance


view_gate = ViewGate()
